# compare instore to online ratio and potential for the online shift before and after covid
#   transactions_ratio >> on a given day, ___ times more people shop instores rather than online (2 line graph showing the trend before and after covid and online vs instore trends)

walmart_melt <- readRDS("baymap/walmart_transactions.rds")
 
ggplot(walmart_melt,aes(x=month,y=value,color=variable,group=variable)) +
geom_line(size=1.5) +
labs(y= "Transactions Ratio", x = "Year-Month", color="Legend") +
theme(axis.text.y =element_blank(),
      axis.ticks.y=element_blank())

pal <- sequential_hcl("red-blue",n=3,rev=T)
col <- colorNumeric(pal,domain=spending_brand_sum$transactions_avg)


fp <- leaflet() %>%
    addProviderTiles(providers$CartoDB.VoyagerLabelsUnder, group = "Default") %>%
    addTiles(urlTemplate = mapbox_sat, attribution = mapbox_satAtt, group = "Satellite") %>%
    addPolygons(
      data = spending_brand_sum,
      color = col(spending_brand_sum$transactions_avg),
      weight=1,
      popup = paste0(
        "<strong>",spending_brand_sum$zip,"</strong><br>",
        spending_brand_sum$transactions_avg),
      labelOptions = labelOptions(
        style = list("font-weight" = "normal", padding = "3px 8px"),
        textsize = "15px",
        direction = "auto"),
      group = "All"
      ) %>%
    addPolygons(
      data = spending_brand_sum_top5,
      weight=2,
      color = "red",
      popup = paste0(
        "<strong>",spending_brand_sum_top5$zip,"</strong><br>",
        spending_brand_sum_top5$transactions_avg),
      labelOptions = labelOptions(
        style = list("font-weight" = "normal", padding = "3px 8px"),
        textsize = "15px",
        direction = "auto"),
      group = "Top 5"
      ) %>%
    addPolygons(
      data = spending_brand_sum_top10,
      color = "red",
      weight=2,
      popup = paste0(
        "<strong>",spending_brand_sum_top10$zip,"</strong><br>",
        spending_brand_sum_top10$transactions_avg),
      labelOptions = labelOptions(
        style = list("font-weight" = "normal", padding = "3px 8px"),
        textsize = "15px",
        direction = "auto"),
      group = "Top 10"
      ) %>%
    addLegend(
      position = 'bottomleft',
      values = spending_brand_sum$transactions_avg,
      pal = col,
      title='Avg Daily Walmart Transactions'
      ) %>%
    addLayersControl(
      baseGroups = c("Default","Satellite"),
      overlayGroups = c("All","Top 5","Top 10")
    ) %>% 
  hideGroup(c("Top 5","Top 10"))

fp